﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MicroConfig.NetCore.Client
{
    public class ConfigItem
    {
        private string _env;
        public ConfigItem(string env)
        {
            _env = env;
            values = new Dictionary<string, string>();
        }

        private Dictionary<string, string> values;

        public string Value(string env)
        {
            values.TryGetValue(env, out string value);
            if (value == null)
            {
                values.TryGetValue("", out value);
            }
            return value;
        }
        internal void Value(string env, string value)
        {
            values[env] = value;
        }

        public string Value()
        {
            return Value(_env);
        }

        public int Int32Value()
        {
            return int.Parse(Value());
        }

        public long Int64Value()
        {
            return long.Parse(Value());
        }

        public double DoubleValue()
        {
            return double.Parse(Value());
        }

        public DateTime DateTimeValue()
        {
            return DateTime.Parse(Value());
        }

        public bool BoolValue()
        {
            return bool.Parse(Value());
        }


        public override string ToString()
        {
            return Value();
        }
    }
}
